package site.brood.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import site.brood.user.pojo.entity.Role;
import site.brood.user.pojo.entity.User;

import java.util.List;
import java.util.Set;

public interface UserMapper extends BaseMapper<User> {

    //查询用户所属角色列表
    @Select("select r.* " +
            " from user u,role r, user_role ur " +
            " where u.id=ur.user_id " +
            " and ur.role_id = r.id" +
            " and u.deleted = 0 " +
            " and r.deleted = 0 " +
            " and u.id=#{userId} ")
    List<Role> selectRolesByUserId(Long userId);

    //通过用户所属角色查询用户可访问菜单功能点的权限列表
    //系统->配置->添加菜单功能点权限格式：system:config:add
    @Select("select distinct m.perms " +
            " from menu m " +
            " left join role_menu rm on m.menu_id = rm.menu_id " +
            " left join user_role ur on rm.role_id = ur.role_id " +
            " left join role r on r.id = ur.role_id " +
            " where m.status = '0' and r.status = '0' and ur.user_id = #{userId}")
    Set<String> selectMenuPermsByUserId(Long userId);
}
